import 'package:flutter/material.dart';
import 'package:flutter_09_game/config/app_routes.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/pages/home/home_logic.dart';
import 'package:flutter_09_game/pages/home/widgets/home_prize_pool.dart';
import 'package:flutter_09_game/user/app_user_manager.dart';
import 'package:flutter_09_game/utils/extensions/num_ext.dart';
import 'package:flutter_09_game/widgets/appbar/common_app_bar.dart';
import 'package:flutter_09_game/widgets/button/common_button.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_09_game/widgets/widget_user_wallet.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../config/app_color.dart';
import '../../../widgets/button/debounce_gesture_detector.dart';

class HomeTopBar extends StatelessWidget {
  const HomeTopBar({super.key, required this.logic});

  final HomeLogic logic;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 52.w + ScreenUtil().statusBarHeight,
      padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight, right: 16.w),
      color: AppColor.navBgColor,
      child: Row(
        // mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            width: 150.w,
            height: double.infinity,
            decoration: const BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(
                      Assets.commonBackBg,
                    ),
                    fit: BoxFit.cover)),
            child: Row(
              children: [
                6.horizontalSpace,
                AutoImage(
                  Assets.commonAppname,
                  width: 32.w,
                ),
                4.horizontalSpace,

                // Logo文字
                Text(
                  'U9.GAME',
                  style: TextStyle(
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w800,
                    color: AppColor.textPrimary.withOpacity(0.94),
                    fontFamily: 'Poppins',
                  ),
                ),
              ],
            ),
          ),
          // Logo区域
          // _buildLogo(),
          const Spacer(),
          Obx(() {
            return AppUserManager().user.value != null
                ?  const WidgetUserWallet()
                : _buildAuthButtons();

          })
        ],
      ),
    );
  }

  // Widget _buildUser() {
  //   return Row(
  //     children: [
  //       const WidgetUserWallet(),
  //       8.horizontalSpace,
  //       GestureDetector(
  //         onTap: () {},
  //         child: AutoImage(
  //           Assets.homeCountryCn,
  //           width: 32.w,
  //         ),
  //       )
  //     ],
  //   );
  // }

  Widget _buildAuthButtons() {
    return Row(
      children: [
        CommonButton(
          width: 72.w,
          height: 32.w,
          title: LocaleKeys.login.tr,
          fontSize: 12.sp,
          enable: false,
          alwaysCanClick: true,
          onClick: () {
            Get.toNamed(AppRoutes.loginPage);
          },
        ),
        // 登录按钮
        // _buildLoginButton(),

        8.horizontalSpace,
        CommonButton(
          width: 72.w,
          height: 32.w,
          title: LocaleKeys.register.tr,
          fontSize: 12.sp,
          alwaysCanClick: true,
          onClick: () {
            Get.toNamed(AppRoutes.loginPage,
                arguments: {'isRegisterType': true});
          },
        ),
        // 注册按钮
        // _buildRegisterButton(),
      ],
    );
  }
}
